import { areaList } from '../api/common';
let cityObj = []
//城市检索的首字母
let searchLetter = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"]

//对城市信息进行分组
async function cityList(callback) {
    await areaList().then(res => {
        cityObj = res.data.result;
    })
    let tempObj=[];
    for (let i = 0; i < searchLetter.length; i++) {
        let initial = searchLetter[i];
        let cityInfo = [];
        let tempArr = {};
        tempArr.initial = initial;
        for (let j = 0; j < cityObj.length; j++) {
            if (initial == cityObj[j].pinyin.charAt(0).toUpperCase()) {
                cityInfo.push(cityObj[j]);
            }
        }
        tempArr.cityInfo = cityInfo;
        tempObj.push(tempArr);
    }
    callback(tempObj)
}
module.exports = {
    searchLetter: searchLetter,
    cityList: cityList
}